<div class="layui-form" lay-filter="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <script type="text/html" template>
        <div class="layui-form-item" hidden>
            <label class="layui-form-label">课程代码</label>
            <div class="layui-form-text layui-input-inline" id="classCode">{{ d.params.classCode }}</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">校区</label>
            <div class="layui-form-mid layui-form-text">{{ d.params.campus }}</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">课程</label>
            <div class="layui-input-inline layui-form-mid">{{ d.params.className }}</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">教师</label>
            <div class="layui-form-mid layui-form-text">{{ d.params.teacher }}</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学分</label>
            <div class="layui-form-mid layui-form-text">{{ d.params.credit }}</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-form-text layui-input-inline" style="top: 8px">{{ d.params.remark }}</div>
        </div>
    </script>
    <div class="layui-form-item" id="coinDiv" hidden>0</div>
    <div class="layui-form-item" id="item-coin" hidden>
        <label class="layui-form-label">投币</label>
        <div class="layui-input-inline" id="slider-coin" style="padding: 16px;">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">购书</label>
        <div class="layui-input-block">
            <input type="checkbox" name="buy" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">调剂</label>
        <div class="layui-input-block">
            <input type="checkbox" name="adjust" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">重修</label>
        <div class="layui-input-block">
            <input type="checkbox" id="retake" lay-filter="retake" name="retake" lay-skin="switch" lay-text="是|否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <input type="button" lay-submit lay-filter="LAY-user-back-submit" value="确认" class="layui-btn">
    </div>
</div>

<script>
    layui.use(['admin', 'form', 'slider'], function(){
        var form = layui.form, $ = layui.$, slider = layui.slider;
        var load = layer.load(2);
        $.ajax({
            url: "/jw/stu/coins",
            dataType: 'json',
            complete: function (result) {
                layer.close(load);
                result = result.responseJSON;
                if (result['status'] === 200) {
                    var restCoin = result.data.rest;
                    var rest = parseInt(restCoin);
                    if (rest > 0) {
                        $('#item-coin').removeAttr("hidden");
                        slider.render({
                            elem: '#slider-coin',
                            max: rest,
                            input: true,
                            change: function (value) {
                                $('#coinDiv')[0].textContent = value
                            }
                        })
                    }
                }else {
                    layer.msg(result['message'])
                }

            }
        });
        form.render();

        form.on('switch(retake)', function (data) {
            var classCode = $('#classCode').text();
            $.ajax({
                url: "/jw/stu/course/retake/" + classCode,
                complete: function (result) {
                    result = result.responseJSON;
                    if (!result.data) {
                        layer.msg("不可重修");
                        data.elem.checked = false;
                        data.elem.disabled = true;
                        form.render();
                    }
                }
            })
        });
        $('.layui-layer.layui-layer-page.layui-layer-admin')[0].style.top = "0px";
    });
</script>